/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package com.l2device.gameserver.handler.voicedcommandhandlers;

import com.l2device.gameserver.handler.IVoicedCommandHandler;
import com.l2device.gameserver.model.actor.instance.L2PcInstance;
import com.l2device.gameserver.model.events.tvt.EventCommons;
import com.l2device.gameserver.model.events.tvt.EventManager;
import com.l2device.gameserver.model.events.tvt.EventState;
import com.l2device.gameserver.model.events.tvt.TvTEvent;
import com.l2device.gameserver.network.serverpackets.NpcHtmlMessage;

/**
 * @author Anarchy
 * @rework Disco
 */
public class EventCommands implements IVoicedCommandHandler
{
	private static String[] _voicedCommands = { "tvt", "tvtjoin","tvtleave" };
      
    @Override
    public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
    {
    	if (activeChar.isInOlympiadMode())
    	{
    		return false;
    	}
	
    	if(command.equalsIgnoreCase("tvt"))
    	{
    		NpcHtmlMessage html = new NpcHtmlMessage(0);
			html.setFile("data/html/mods/tvt/tvtinfo.htm");
			activeChar.sendPacket(html);
    	}
    	if(command.equalsIgnoreCase("tvtjoin"))
    	{
    		if (EventManager.getInstance().getCurrentEvent() == null || EventManager.getInstance().getCurrentEvent().getState() != EventState.REGISTERING)
    			return false;             
    		EventCommons.getInstance().registerPlayer(activeChar, TvTEvent.class);
    		activeChar.sendMessage("Вы зарегистрированы на TvT ивент.");    		
    	
    	}
    	if(command.equalsIgnoreCase("tvtleave"))
    	{
    		if (EventCommons.getInstance().getRegisteredPlayers().containsKey(activeChar))
    			EventCommons.getInstance().unregisterPlayer(activeChar,EventCommons.getInstance().getRegisteredPlayers().get(activeChar));
    		
    		activeChar.sendMessage("Регистрация на TvT ивент отменена.");
    	}
    	return true;
    }
    
    @Override
    public String[] getVoicedCommandList()
    {
    	return _voicedCommands;
    }
}